const formatFormDict = {
    condition1: (form: any, min = 0) => {
        return form.ruleInfo === '1' ? '' : String(form.num1 ?? min)
    },
    condition2: (form: any, min = 0) => {
        return form.ruleInfo === '1' ? '' : `${form.num1 ?? min},${form.num2 ?? min}`
    },
    condition3: (form: any, min = 0) => {
        return form.ruleInfo === '1' ? '' : `1,${form.num1 ?? min}`
    },
}
const formatRuleInfoDict = {
    condition1: (ruleInfo: any, form: any) => {
        if (ruleInfo) {
            form.num1 = Number(ruleInfo)
            form.ruleInfo = '2'
        }
        else {
            form.ruleInfo = '1'
        }
    },
    condition2: (ruleInfo: any, form: any) => {
        if (ruleInfo) {
            const arr = ruleInfo.split(',')
            form.num1 = Number(arr?.[0])
            form.num2 = Number(arr?.[1])
            form.ruleInfo = '2'
        }
        else {
            form.ruleInfo = '1'
        }
    },
    condition3: (ruleInfo: any, form: any) => {
        if (ruleInfo) {
            const ruleArr = ruleInfo.split(',')
            form.num1 = Number(ruleArr?.[1])
            form.ruleInfo = '2'
        }
        else {
            form.ruleInfo = '1'
        }
    },
}
export const nameEnum = {
    1: {
        formatDetail: (row: any) => {
            if (row?.ruleInfo)
                return `自获取积分起,${row?.ruleInfo}年后的12月31日失效`
            return '永久有效'
        },
        formatForm: formatFormDict.condition1,
        formatRuleInfo: formatRuleInfoDict.condition1,
        label: '积分有效期',
    },
    2: {
        formatDetail: (row: any) => {
            if (row?.ruleInfo) {
                const ruleArr = row?.ruleInfo?.split(',')
                return `所有会员统一抵扣规则\n每${ruleArr?.[0]}个积分可抵现1元,每笔订单最多使用积分抵现${ruleArr?.[1]}%`
            }
            return '不可抵现'
        },
        formatForm: formatFormDict.condition2,
        formatRuleInfo: formatRuleInfoDict.condition2,
        label: '抵扣规则',
    },
    3: {
        formatDetail: (row: any) => {
            if (row?.ruleInfo) {
                const getArr = row?.ruleInfo?.split(',')
                return `每个客户每天最多获得${getArr?.[1]}积分`
            }
            return '无上限'
        },
        formatForm: formatFormDict.condition3,
        formatRuleInfo: formatRuleInfoDict.condition3,
        label: '获取上限',
    },
    4: {
        formatDetail: (row: any) => {
            if (row?.ruleInfo)
                return `积分发放后将进入${row?.ruleInfo}天保护期`

            return '无保护期'
        },
        formatForm: formatFormDict.condition1,
        formatRuleInfo: formatRuleInfoDict.condition1,
        label: '积分保护期',
    },
    5: {
        formatDetail: (row: any) => {
            return `每成功下单一笔,奖励${row?.ruleInfo}积分`
        },
        formatForm: formatFormDict.condition1,
        formatRuleInfo: formatRuleInfoDict.condition1,
        label: '完成下单奖励',
    },
    6: {
        formatDetail: (row: any) => {
            const buyArr = row?.ruleInfo?.split(',')
            return `单笔订单每满${buyArr?.[0]}元,奖励${buyArr?.[1]}积分`
        },
        formatForm: formatFormDict.condition2,
        formatRuleInfo: formatRuleInfoDict.condition2,
        label: '购买商品奖励',
    },
} as const
